using UnityEngine;
using System.Collections;

public class Bomb : MonoBehaviour {
	
	float dice;
	
	bool once;
	
	Vector3 positionOrigin;
	//Vector3 positionOrigin;
	Vector3 rotationOrigin;
	
	bool reset;
	
	// Use this for initialization
	void Start () {
		
		positionOrigin = transform.position;
		rotationOrigin = Vector3.zero;
		reset= false;
	
	}
	
	// Update is called once per frame
	void Update () {
		
		if( (!once && Rat.fuck==0) ) {
			transform.position=positionOrigin;
			transform.Rotate(rotationOrigin);
			transform.rigidbody.useGravity = false;
			renderer.enabled=true;
			collider.enabled=true;
		}else {
			transform.position= new Vector3(Rat.RatPosition.x, transform.position.y, transform.position.z);
		}
		
		
		if(reset){
			transform.position=positionOrigin;
			transform.Rotate(rotationOrigin);
			transform.rigidbody.useGravity = false;
			
			reset=false;
			
		}
	
	}//Update
	
	void FixedUpdate (){
		
		if (once){
			dice = Random.Range(1,59); 
			once =false;
		}
		
		
		
		if(Rat.fuck==1){  //variavel dentro de rato tipo inteira
			if(!once){
				if(dice==WheelRotation.CounterFrame){
				transform.rigidbody.useGravity = true;
				}
			}
			
			
			once=true;	
			
			
		}else if (Rat.fuck==0){
			once=false;
		}
		
	}//FixedUpdate
	
	

	void OnCollisionEnter(Collision collision){
		
		if(collision.transform.tag=="cabin" || collision.transform.tag=="falseCollision"  ){
			transform.position=positionOrigin;
			transform.Rotate(rotationOrigin);
			transform.rigidbody.useGravity = false;
			collider.enabled=false;
			renderer.enabled=false;
			reset = true;
		}
	}
	
}
